#ifndef OPENGL_H
#define OPENGL_H

#include "Basic/GxLibBasic.h"
#include "gl/gl.h"
#include "gl/glu.h"
#include "LibGL/glLoader.h"
#include "LibGL/GxTextures.h"
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")

namespace GxRendering
{
	using namespace GxLibBasic;
	class RenderBuffer : public Object
	{
	private:
		unsigned int rb;
		int itnFmt;
	public:
		RenderBuffer(int internalFormat, int w, int h);
		~RenderBuffer();
		unsigned int GetHandle();
		void SetStorage(int w, int h);
	};

	class FrameBufferObject : public Object
	{
	private:
		unsigned int fbo;
		unsigned int lstFBO;
	public:
		FrameBufferObject();
		~FrameBufferObject();
	public:
		void AttachTexture(unsigned int attachment, GLuint texID, unsigned int texTarget = GL_TEXTURE_2D, int level = 0);
		void AttachTexture(unsigned int attachment, Texture * tex, unsigned int texTarget = GL_TEXTURE_2D, int level = 0);
		void AttachRenderBuffer(unsigned int attachment, RenderBuffer * rb);
		bool IsReady();
		void Bind();
		void UnBind();
	};

	class OpenGL : public Object
	{
	public:
		enum GLVersion
		{
			gvOlder, gv100, gv110, gv120, gv130, gv140, gv150, gv200, gv210, gv300, gv310, gvNewer
		};
		static PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;
		static PFNGLENABLEIPROC Enablei;
		static PFNGLDISABLEIPROC Disablei;
		static PFNGLDRAWBUFFERSPROC DrawBuffers;
		static PFNGLCLAMPCOLORARBPROC ClampColor;
		static PFNGLGENERATEMIPMAPEXTPROC GenerateMipmap;
		static PFNGLGETCOMPRESSEDTEXIMAGEPROC GetCompressedTexImage;
		static PFNGLCOMPRESSEDTEXIMAGE2DPROC CompressedTexImage2D;
	public:
		static bool Init();
		static GLVersion GetVersion();
		static String GetRenderer();
		static void SetSwapInterval(int inter);
	};

	void BeginUIDrawing();
	void EndUIDrawing();
}

#endif